
<div class="xinxi-guanli">
<div class="xinxi-title">
	
	<ul id="details-ul" class="clearfix">
		<li class="hover"><a href="javascript:void(0);">发布新闻</a></li>
		<li><a href="/news/index">管理新闻</a></li>
	</ul>
</div>
 <div id="details-con-1" class="xinxi-guanli-box">
<form id="applyform" action="" method="post" onsubmit="return addContent();">
<table class="grinfo">

  <tbody>
		<tr>
				    <th>缩略图：</th>
					<td>
                        <div class="imgicon">
						
						<div>
						<ul class="s_pic"><li id="iconlists"></li></ul>
						<input type="hidden" value=""   id="thumb"  name="thumb" >
						</div>
						<br/>
							<div style="float:left;">
                            <div id="uploadposter" >
		                        <input type="text" size="10"   id="icon"  name="icon" >
		                       
		                   </div>
						</div>
						
						<br/>
						<br/>
                        <p class="f_prompt fgrey"><i class="icon i_s_plaint"></i>注意：缩略图宽高大小必须在100*100到500*500之间的图片。</p>
                        </div>
                        
                    </td>
    </tr>
	<tr>
		<th><span class="red">*</span>新闻栏目：</th>
		<td colspan="2">
		<select id="catid" class="inp inw" style="width:85px;" name="catid">
		{$Categoryhtml}
		</select>
		</td>
	</tr>
	
	<tr>
		<th><span class="red">*</span>标题：</th>
		<td><input type="text" value="" id="title" style="width:480px;" name="title" class="inp inw"></td>
	</tr>
	
	<tr>
		<th><span class="red">*</span>关键词：</th>
		<td><input type="text" value="" id="keywords" style="width:480px;" name="keywords" class="inp inw">
			<span class="fgrey" id="keywordsthtml" >多个关键词请以逗号(,)分开</span></td>
	</tr>

	<tr>
		<th valign="top"><span class="red">*</span>摘要：</th>
		<td>
			<textarea name="description" class="grtextarea" style="width:600px;height:60px;" id="description"> </textarea>
			<br>
			<span class="fgrey" id="descriptionhtml" >(注:新闻摘要为内容的简单说明，不能少于20个字)</span>
		</td>
	</tr>

	<tr>
		<th valign="top"><span class="red">*</span>内容：</th>
		<td>
			<textarea name="content" class="grtextarea" style="width:505px;height:280px;" id="content"> </textarea>
			<span id="contenthtml" class="fgrey"><span class="red">*</span>&nbsp;&nbsp;详细说明不能少于50个字。
温馨提示：为保证您发布内容格式的正确，请直接在编辑窗口中进行编辑，不要直接粘贴从word里复制的内容！</span>
		</td>
	</tr>



	
	
	
	<tr>
		<th>&nbsp;</th>
		<td colspan="2">
			<label id="butt" class="butt">
				<input type="submit" name="btnSubmit" value="确定发布" id="btnSubmit" class="btns">
			</label>
		</td>
	</tr>
</tbody>
</table>

{__TOKEN__}
</form>

  </div>
  
    
</div>

<script type="text/javascript" src="/public/js/plugin/jquery.uploadify-3.1.min.js"></script>
<script type="text/javascript" src="/public/js/plugin/tinymce/tinymce.min.js"></script>
<script type="text/javascript" src="/public/js/plugin/layer/jquery.layer.js"></script>
<script type="text/javascript" src="/public/js/plugin/jquery.form.js"></script>
<script type="text/javascript" src="/public/js/plugin/jquery.validate.js"></script>
<script type="text/javascript" src="/public/js/product.js"></script>
<script type="text/javascript">
function addContent()
{
	var content = tinyMCE.get('content').getContent();
    $("#content").val(content);
}

//选取文件的函数，后台特有
tinymce.init({
    selector: "textarea#content",
    theme: "modern",
	language :"zh_CN",
    width: 600,
    height: 300,
    plugins: [
         "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
         "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
         "save table contextmenu directionality emoticons template paste textcolor"
   ],
   content_css: "css/content.css",
   toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | l      ink image | print preview media fullpage | forecolor backcolor emoticons", 
   style_formats: [
        {title: 'Bold text', inline: 'b'},
        {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
        {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
        {title: 'Example 1', inline: 'span', classes: 'example1'},
        {title: 'Example 2', inline: 'span', classes: 'example2'},
        {title: 'Table styles'},
        {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
    ]
 });   

$(document).ready(function(){
	
	


	$("#icon").uploadify(
        {
    		swf              : '/public/js/plugin/uploadify.swf',
    		uploader         : "/public/thumb",
    		cancelImg        : '/public/images/cancel.gif',
    		formData      : {'uid' : '3551726'},
            queueID          : 'fileIcon',
            removeTimeout 	 : 0,
			debug    : 0,
            method	         : 'POST',
            fileTypeDesc	 : '注意:您只能上传jpeg,png,gif格式的文件!',
            fileTypeExts	 : '*.jpg;*.jpeg;*.gif;*.png',
		    buttonImage	 	 : '/public/images/upload_file.png',
            width			 : '100',
            height		     : '35',	
            auto             : true,
            onUploadSuccess  : function(file, data, response) {
                {
                    var response=eval("("+data+")");
                    if(response.status){
                        $('#iconlists').html('<img src="http://user.dushijia.com/Public/Uploads'+response.info+'"    width="150"   height="150" >');  
                        $('#thumb').val(response.info);
    				} else {
                        $('#iconlists').html('<font color="red">'+response.info+'</font>');
				    }
                }
         }
       
     });
	





	$("#applyform").validate({
	  		focusInvalid: true ,
			errorClass: "err_ipt",
			ignore: "",
			rules: {
				'catid': {
	                required: true,
					digits: true
	            },
				'title':{
					required: true,
					minlength:5
				},
				'keywords':{
					required: true,
					minlength:2
				},
				'description':{
					required: true,
					minlength:20
				},
				'content':{
					required: true,
					minlength:50
				}
	        },   
	        messages: {
				'catid': {
					required: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请选择新闻分类.</span>',
					digits: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请选择新闻分类.</span>'
				},
	        	'title':{
	        		required:'<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请填写新闻信息标题.</span>',
	        		minlength: jQuery.format('<span class="fgrey"><img src="/public/images/error.gif" />&nbsp;新闻信息标题不得少于{0}个字.</span>')
	            },
				'keywords':{
	        		required:'<span class="fgrey"><img src="/public/images/error.gif" />&nbsp;多个关键词请以逗号(,)分开.</span>',
	        		minlength: jQuery.format('<span class="fgrey"><img src="/public/images/error.gif" />&nbsp;关键词不得少于{0}个字.</span>')
	            },
				'description':{
	        		required:'<span class="fgrey"><img src="/public/images/error.gif" />&nbsp;产品摘要为产品介绍的简单说明，不能少于20个字.</span>',
	        		minlength: jQuery.format('<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 产品摘要为产品介绍的简单说明，不能少于{0}个字.</span>')
	            },
				'content':{
	        		required:'<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请填写新闻介绍,且文字不能少于50个字.</span>',
	        		minlength: jQuery.format('<span class="fgrey"><img src="/public/images/error.gif" />&nbsp;新闻介绍信息不得少于{0}个字.</span>')
	            }
				
			},
			errorPlacement: function(error, element) {
				
				if ($(element).attr("name")=='catid') {
					if(parseInt($("#catid").val())==0){
						$("#catidhtml").html(error);
						return true;
					}
		        }

				if ($(element).attr("name")=='keywords') {
					$("#keywordsthtml").html(error);
					return true;
		        }

				if ($(element).attr("name")=='content') {
		        	tinyMCE.get('content').focus();
					$("#contenthtml").html(error);
					return true;
		        }
		        
		        error.insertAfter(element);
		    },
			success: function(label) {
				label.html('<span class="f_prompt"><img src="/public/images/yes.gif" /></span>').addClass("success");
			},
			submitHandler: function(form) {
				
				jQuery(form).ajaxSubmit({
					target: "#result",
					beforeSubmit:disableForm,
			        success:submitForm, 
			        url:'/news/add',       
			        type:'post',      
			        dataType:'json'
				});
			}
		});
	  	function disableForm(){
			//$('#applyform').find("input[type='submit']").attr("disabled",true);
			$('#applyform').find("input[type='submit']").val("正在发布,请稍等...");
			$.layer({
				v_title:'发布中',
				v_btns:0,
				v_msgtype:0,
				v_shade:false,
				v_area : ['300px','150px'],
				v_msg:'<div class="">\
							<div class="">\
							   <font color="green">数据正在提交到服务器进行发布,<br/>请耐心等待...</font>\
							</div>\
						</div>'
			});
			return true; 
		}

		function submitForm(responseText)  { 
			layer_close(true);
			if(responseText.status){
				if(responseText.data.id){
					$.layer({
						v_msg:responseText.info,
						v_title:'信息发布成功',
						v_btns:2,
						v_shade:false,
						v_btn:['返回列表','继续发布'],
						v_area:['410px','220px'],
						yes:function(){
							layer_close(true);
							location.href ="/news/index";
						},
						no:function(){
							location.href = '/news/add';
						}
					});
				}else{
					$.layer({v_msg:responseText.info,v_shade:false,v_title:'信息发布出错',v_showtime:2});
				}
				
			}else{
				
				$.layer({v_msg:responseText.info,v_shade:false,v_title:'信息发布出错',v_showtime:2});

				if(responseText.data.inputName == 'content'){
					tinyMCE.get('content').focus();
				}else{
					$("#"+responseText.data.inputName).focus();
				}
				//$('#applyform').find("input[type='submit']").attr("disabled",false);
				$('#applyform').find("input[type='submit']").val("发布新闻");
			}
		}


		
 });	
 </script>